/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cs;

import java.util.Scanner;

/**
 *
 * @author QuangHieu
 */

class DNode{
    int data;
    DNode next,pre;
    DNode(int x){
        data=x;
        next=null; pre=null;
    }

    DNode (int x, DNode t){
        t.data=x;
        if(t==null){
            next=null; pre=null;
        }
        else {
            next=t;
            t.pre=this;
        }
    }
}

public class MyDoubleList {

    DNode head, tail;

    public MyDoubleList() {
        head=tail=null;
    }

    void append(int x){
        DNode t=new DNode(x);
        if(head==null) head=tail=t;
        else {
            tail.next=t;
            t.pre=t;
            tail=t;
        }
    }

    void taoDS(){
        head=tail=null;
        int x,i=1;
        Scanner kb=new Scanner(System.in);
        while(true){
            System.out.print("\nNhap so thu "+(i++) + ":");
            x=kb.nextInt();
            if(x!=0) append(x);
            else break;
        }
    }

    public String toString(){
        String t = "==>";
        DNode p = head;
        while (p != null) {
            t = t + p.data + "==>";
            p = p.next;
        }
        t = t + "null";
        return t;
    }

    public static void main(String []agrs){
        MyDoubleList ml=new MyDoubleList();
        ml.taoDS();
        System.out.print("\nDanh sach: " + ml);
        ml.append(100);
        System.out.print("\nDanh sach moi: " + ml);
    }


}
